class DjinnsController < ApplicationController
  # GET /djinns
  # GET /djinns.xml
  def index
    @djinns = Djinn.find(:all).sort_by{ |i| i[:name] }.sort_by{|x| x[:element]}

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @djinns }
    end
  end

  # GET /djinns/1
  # GET /djinns/1.xml
  def show
    @djinn = Djinn.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @djinn }
    end
  end

  # GET /djinns/new
  # GET /djinns/new.xml
  def new
    @djinn = Djinn.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @djinn }
    end
  end

  # GET /djinns/1/edit
  def edit
    @djinn = Djinn.find(params[:id])
  end

  # POST /djinns
  # POST /djinns.xml
  def create
    @djinn = Djinn.new(params[:djinn])

    respond_to do |format|
      if @djinn.save
        flash[:notice] = 'Djinn was successfully created.'
        format.html { redirect_to(@djinn) }
        format.xml  { render :xml => @djinn, :status => :created, :location => @djinn }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @djinn.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /djinns/1
  # PUT /djinns/1.xml
  def update
    @djinn = Djinn.find(params[:id])

    respond_to do |format|
      if @djinn.update_attributes(params[:djinn])
        flash[:notice] = 'Djinn was successfully updated.'
        format.html { redirect_to(@djinn) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @djinn.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /djinns/1
  # DELETE /djinns/1.xml
  def destroy
    @djinn = Djinn.find(params[:id])
    @djinn.destroy

    respond_to do |format|
      format.html { redirect_to(djinns_url) }
      format.xml  { head :ok }
    end
  end
end
